package one2Ten;

/**
 * 输入一个二维数组，与一个数字，判断数组中是否存在该数字
 * Created by Wongy on 2018/3/9.
 */
public class Three3 {
    private static boolean isExist(Integer[][] integers, Integer integer) {
        if (integers == null) {
            return false;
        }
        int count = 0;
        int rowCount = 0;
        int colCount = integers[0].length - 1;
        while (colCount >= 0 && rowCount < integers.length) {
            if (integers[rowCount][colCount] == integer) {
                System.out.println("Three3.isExist , 19 : colCount = " + colCount + " , rowCount = " + rowCount);
                count++;
                colCount--;
                rowCount++;
            } else if (integers[rowCount][colCount] > integer) {
                colCount--;
            } else {
                rowCount++;
            }
        }
        System.out.println("Three3.isExist , 37 : all numer is :" + count);
        return count > 0;
    }

    public static void main(String[] args) {
        Integer[][] integers = new Integer[4][4];
        integers[0][0] = 1;
        integers[0][1] = 2;
        integers[0][2] = 8;
        integers[0][3] = 9;

        integers[1][0] = 2;
        integers[1][1] = 4;
        integers[1][2] = 9;
        integers[1][3] = 12;

        integers[2][0] = 4;
        integers[2][1] = 7;
        integers[2][2] = 10;
        integers[2][3] = 13;

        integers[3][0] = 7;
        integers[3][1] = 8;
        integers[3][2] = 11;
        integers[3][3] = 15;

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                System.out.print(integers[i][j] + "    ");
            }
            System.out.println();
        }


        System.out.println(isExist(integers, 7));
    }
}
